package com.hoongs.v1.entity;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.hoongs.v1.utils.DateUtil;
import com.hoongs.v1.vo.OrderVo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Repository;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Repository
@TableName(value = "socket_msg_record")
public class SocketMsgRecord {

    private String id;

    @TableField(value = "msg_id")
    private String msgId;          // 关联消息ID

    @TableField(value = "from_id")
    private String fromId;          // 发送人ID
    @TableField(value = "from_name")
    private String fromName;        // 发送人名称

    @TableField(value = "is_read")
    private String isRead = "0";     // 是否已读

    @TableField(value = "to_id")
    private String toId;            // 接收人ID
    @TableField(value = "to_name")
    private String toName;          // 接收人名称

    @TableField(value = "pc_link")
    private String pcLink;        // PC处理链接

    @TableField(value = "app_link")
    private String appLink;        // 小程序处理链接

    private String title;         // 标题

    private String content;         // 内容

    private String type;            // 类型   1:系统消息 2:用户消息

    private String actionType;      // 内容类型   88:新订单、90:商家取消订单、91:用户取消订单、100:设置已读、101:设置未读

    private String remark;         // 内容

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private LocalDateTime createTime;       // 发布时间

    @JsonFormat(pattern = DateUtil.PATTERN_DATETIME)
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATETIME)
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updateTime;    // 更新时间


    public static SocketMsgRecord fromMsg(SocketMsg socketMsg) {
        SocketMsgRecord socketMsgRecord = BeanUtil.copyProperties(socketMsg, SocketMsgRecord.class);
        socketMsgRecord.setMsgId(socketMsg.getId());
        socketMsgRecord.setId(null);
        return socketMsgRecord;
    }
}
